package com.fyt.video.project.util;

import com.fyt.video.project.pojo.Device;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectUtil<T> {

    public T ref(Class<T> clazz,String method,String value) throws Exception {
        T t = clazz.newInstance();

        Method[] methods = t.getClass().getMethods();
        for (Method m : methods) {
            String name = m.getName();
//            System.out.println(name);
            if (name.equals(method)){
                m.invoke(t,"8000");
            }
        }

        Field[] fields = t.getClass().getFields();
        for (Field f:
             fields) {
            String name = f.getName();
            Class<?> type = f.getType();
            Object cast = type.cast(value);
            System.out.println(cast);
        }
        return t;
    }

    public static void main(String[] args) throws Exception {
        ReflectUtil util = new ReflectUtil();
        Device getPort = (Device) util.ref(Device.class, "setDrud","800");
        System.out.println(getPort.getPort());
    }
}
